#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int n = nums.size();

        vector<int>fmax(n), gmin(n);
        fmax[0] = gmin[0] = nums[0];
        int ret = INT_MIN;
        for (int i = 1; i < n; i++)
        {
            int x = nums[i], y = fmax[i - 1] * nums[i], z = gmin[i - 1] * nums[i];
            fmax[i] = max(x, max(y, z));
            gmin[i] = min(x, min(y, z));
            ret = max(ret, fmax[i]);
        }
        ret = max(fmax[0], ret);
        return ret;
    }
};